package com.gc.controller.booksellerSevlet;


import com.gc.entity.BookSeller;
import com.gc.repository.BookSellerRepository;
import com.gc.repository.impl.BookSellerRepositoryImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "booksellerAdd", value = "/booksellerAdd")
public class booksellerAdd extends HttpServlet {
    BookSellerRepository booksellerRepository = new BookSellerRepositoryImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("yes!!");
        Gson gson = new Gson();

        /**
         *   long id;
         *     String name;
         *     String sid;
         *     String sex;
         *     String age;
         *     String password;
         *     String phone;
         *     String email;
         */
        boolean res = booksellerRepository.Add(new BookSeller(
                null,
                request.getParameter("name"),
                request.getParameter("bid"),
                request.getParameter("password"),
                request.getParameter("phone"),
                request.getParameter("email")));
        if(res) {
            response.getWriter().write(gson.toJson(R.ok().data("ok")));
        } else {
            response.getWriter().write(gson.toJson(R.error()));
        }


    }
}
